package com.dt76.smallloanbackenduser.controller.zjs;

import com.dt76.smallloanbackenduser.remote.zjs.BlackUserRemote;
import com.dt76.smallloanbackenduser.utils.Page;
import com.dt76.smallloanbackenduser.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/zjs")
public class BlackUserController {

    @Autowired
    private BlackUserRemote blackUserRemote;

    @RequestMapping("/blackUser")
    @ResponseBody
    public String getAll(Model model){
        model.addAttribute("qryAllList",blackUserRemote.qryAllBlackUser());
        System.out.println("調用遠程服務成功");
        System.out.println(blackUserRemote.qryAllBlackUser());
        return "pages/zjs/blackUser";
    }


    @RequestMapping("/qryPageAll")
    public String qryPageAll(Model model,@RequestParam(defaultValue = "1") Integer currentPageNo,
                                      @RequestParam(value = "queryname",required = false)String queryname,
                                     @RequestParam(value = "queryUserId",required = false)String queryUserId) {



        if (currentPageNo<=0){
            currentPageNo=1;
        }
        //02.调用动态查询+分页查询接口
        String paramName = "";
        if(queryname != null && !queryname.equals("")){
            paramName = "%"+queryname+"%";
        }
        if(queryUserId == null || queryUserId.equals("")){queryUserId = "0";}
        System.out.println(paramName);

        Page page = blackUserRemote.qryPageAllBlackUser(currentPageNo, paramName, Integer.valueOf(queryUserId));

        //03.组织返回值
        model.addAttribute("queryPageList", page.getRows());//用户列表
        model.addAttribute("page", page);
        //加入动态查询条件返回
        model.addAttribute("queryname",queryname);
//        model.addAttribute("queryuserId",queryUserId);
        System.out.println(page.getRows());
        System.out.println(page);
        return "pages/zjs/blackUser";
    }




        @RequestMapping("/delBlackUser/{userId}")
        @ResponseBody
        public Result delete(@PathVariable String userId){


            return blackUserRemote.delBlackUser(Integer.parseInt(userId));
        }

}
